﻿using System.Collections.Generic;

namespace msilgc.cbuilder
{
    internal static class ExtensionHelpers
    {
        public static int IndexOf<T>(this IEnumerable<T> collection, T val)
        {
            IList<T> list = collection as IList<T>;
            if(list != null)
            {
                return list.IndexOf(val);
            }
            int i = (-1);
            foreach (T possibleVal in collection)
            {
                ++i;
                if(possibleVal.Equals(val))
                {
                    return i;
                }
            }
            return (-1);
        }

        public static void AddRange<T>(this ICollection<T> collection, IEnumerable<T> values)
        {
            List<T> list = collection as List<T>;
            if(list != null)
            {
                list.AddRange(values);
            }
            else
            {
                foreach (T value in values)
                {
                    collection.Add(value);
                }
            }
        }
    }
}
